/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufg.inf.si.poo.formula1.Race;

import br.ufg.inf.si.poo.formula1.Library.Library;

/**
 * Qualification
 * 
 * Versao 1.0
 * 
 * Data 24/01/2013
 * 
 * @author Igor
 */
public class Qualification{
    //Atributos
    private int qttDrivers;
    private GridPosition[] qualification;
    
    //Contrutores
    public Qualification(){
        this.qttDrivers = 0;
        qualification = new GridPosition[26];
    }
    
    //Metodos Getters and Setters
    /**
     * Retorna o atributo qttDrivers (quantidade de pilotos no Qualification)
     * @return o atributo qttDrivers
     */
    public int getQttDrivers() {
        return qttDrivers;
    }

    /**
     *  Retorna o atributo qualification (vetor com os dados da qualificacao da corrida)
     * @return o atributo qualification
     */
    public GridPosition[] getQualification() {
        return qualification;
    }

    /**
     * Adiciona, no vetor qualification, piloto por piloto ate que tenha os 26
     * @param qualification altera o atributo qualification
     */
    public void setQualification(GridPosition qualification) {
        if(this.qttDrivers < 26){
            this.qualification[this.qttDrivers] = qualification;
            this.qttDrivers = this.qttDrivers + 1;
        }
    }

    //Outros Metodos
    /**
     * Reescrita do metodo toStrng
     * Preenche o retorno com os dados do relatorio da qualificacao
     * @return String com o relatório de dados da qualificação
     */
    @Override 
    public String toString(){
        String data = "";

        data += "Pos\tNo\tDriver\t\tTeam\t\tQ1\t\tQ2\t\tQ3\t\tLaps" + "\n";

        for(int i = 0;i < this.qttDrivers;i++){
            if(this.qualification[i] != null){
                if("DNQ".equals(this.qualification[i].getStatus())){
                    data += this.qualification[i].getStatus() + "\t";
                }else{
                    data += this.qualification[i].getStartingPosition() + "\t";
                }
                data += this.qualification[i].getNumberDriver() + "\t";
                if(this.qualification[i].getDriver() == null) {
                    data += "null\t\t";
                }
                else {
                    data += Library.setLengthString(this.qualification[i].getDriver().getDriverName(), 15) + "\t";
                }
                data += Library.setLengthString(this.qualification[i].getDriver().getTeam().getShortName(),15) + "\t";
                data += Library.convertMilliseconds(this.qualification[i].getQ1(),"MINUTOS") + "\t";
                if(!(this.qualification[i].getQ2() == 0)){
                    data += Library.convertMilliseconds(this.qualification[i].getQ2(),"MINUTOS") + "\t";
                }else{
                    data += "\t\t";
                }
                if(!(this.qualification[i].getQ3() == 0)){
                    data += Library.convertMilliseconds(this.qualification[i].getQ3(),"MINUTOS") + "\t";
                }else{
                    data += "\t\t";
                }
                data += this.qualification[i].getQttLapsQualification() + "\t";
                data += "\n";
            }
        }
        return data;
    }
}
